package com.teachoa.core;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.core.JFinal;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.druid.DruidPlugin;
import com.jfinal.render.ViewType;
import com.teachoa.bean.Dict;
import com.teachoa.bean.Menu;
import com.teachoa.bean.RoleMenu;
import com.teachoa.bean.TeacherStudent;
import com.teachoa.bean.User;
import com.teachoa.interceptor.LoginInterceptor;
import com.teachoa.web.DictController;
import com.teachoa.web.IndexController;
import com.teachoa.web.MainController;
import com.teachoa.web.MsgController;
import com.teachoa.web.ProjectController;
import com.teachoa.web.TeachController;
import com.teachoa.web.UserController;

public class TeachoaConfig extends JFinalConfig {

	@Override
	public void configConstant(Constants me) {
		me.setDevMode(true);
		me.setError404View("/error/404.html");
		me.setError500View("/error/500.html");
		me.setViewType(ViewType.JSP);
		me.setBaseViewPath("/WEB-INF/jsp/");
		
	}

	@Override
	public void configRoute(Routes me) {
		me.add("/", IndexController.class);
		me.add("/main", MainController.class);
		me.add("/user", UserController.class);
		me.add("/dict", DictController.class);
		me.add("/teach", TeachController.class);
		me.add("/msg", MsgController.class);
		me.add("/pro", ProjectController.class);
	}

	@Override
	public void configPlugin(Plugins me) {
		loadPropertyFile("config/jdbc.txt");
		DruidPlugin dp = new DruidPlugin(getProperty("jdbcUrl"), getProperty("username"), getProperty("password"));
		me.add(dp);
		ActiveRecordPlugin arp = new ActiveRecordPlugin(dp);
		arp.setShowSql(true);
		arp.setDevMode(true);
		me.add(arp);
		arp.addMapping("user", User.class);
		arp.addMapping("menu", Menu.class);
		arp.addMapping("role_menu", RoleMenu.class);
		arp.addMapping("dict", Dict.class);
		arp.addMapping("teacher_student", TeacherStudent.class);
	}

	@Override
	public void configInterceptor(Interceptors me) {
		me.add(new LoginInterceptor());
	}

	@Override
	public void configHandler(Handlers me) {
		
	}
	
	public static void main(String[] args) {
		JFinal.start("WebContent", 8080, "/", 10);
	}

}
